/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Business.ShowRegion;

import Business.Region.Country.Country;
import Business.Region.Hospital.Hospital;
import Business.Region.Provincy.Provincy;
import Business.RegionOperation.RegionOperation;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author hooting
 */
public class ShowRegion {
	public String[] getCountries(){
		List<Country> countryList = new RegionOperation().getAllCountries();
		if(countryList.size() == 0){
			return null;
		}
		String[] countries = new String[countryList.size()];
		for(int i = 0; i < countryList.size(); i++){
			countries[i] = countryList.get(i).getCountryName();
		}
		return countries;
	}	

	public String[] getProvincies(String country){
		List<Country> countryList = new RegionOperation().getAllCountries();
		Country c = null;
		Iterator<Country> ite = countryList.iterator();
		while(ite.hasNext()){
			Country tempC = ite.next();
			if(country.equals(tempC.getCountryName())){
				c = tempC;
				break;
			}
		}
		if(c == null){
			return null;
		}
		List<Provincy> provincyList = c.getProvincyList();
		String[] provincies = new String[provincyList.size()];
		for(int i = 0; i < provincyList.size(); i++){
			provincies[i] = provincyList.get(i).getProvincyName();
		}
		return provincies;
	}

	public String[] getHospitals(String country, String provincy){
		List<Country> countryList = new RegionOperation().getAllCountries();
		Country c = null;
		Iterator<Country> ite = countryList.iterator();
		while(ite.hasNext()){
			Country tempC = ite.next();
			if(country.equals(tempC.getCountryName())){
				c = tempC;
				break;
			}
		}	
		if(c == null){
			return null;
		}
		List<Provincy> provincyList = c.getProvincyList();
		Iterator<Provincy> iteProvincy = provincyList.iterator();
		Provincy p = null;
		while(iteProvincy.hasNext()){
			Provincy tempP = iteProvincy.next();
			if(provincy.equals(tempP.getProvincyName())){
				p = tempP;
				break;
			}
		}
		if(p == null){
			return null;
		}
		List<Hospital> hospitalList = p.getHospitalList();
		String[] hospitals = new String[hospitalList.size()];
		for(int i = 0; i < hospitalList.size(); i++){
			hospitals[i] = hospitalList.get(i).getHospitalName();
		}
		return hospitals;
	}
	
}
